<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <goods-item v-for="good in hotList" :key="good.id" :good="good" />
  </div>
</template>
<script>
import { computed, onMounted, ref } from 'vue'
import { findHotGoods } from '@/api/goods'
// 在业务数据下共有三种热榜类型，每种热榜类型数据不一样之外，组织结构完全相同
import GoodsItem from '@/views/Category/components/goods-item'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  props: {
    hotType: {
      type: Number,
      default: 1// 1代表热销，2代表周，3代表总
    }
  },
  components: { GoodsItem },
  setup (props) {
    // 定义title和类型的枚举关系
    const hotTitles = { 1: '24小时热销榜', 2: '周热销榜', 3: '总热销榜' }
    const title = computed(() => {
      return hotTitles[props.hotType]
    })
    const hotList = ref([])
    const route = useRoute()
    async function loadData () {
      const res = await findHotGoods({
        id: route.params.id,
        type: props.hotType
      })
      console.log('findHotGoods数据是', res)
      hotList.value = res.data.result
    }
    onMounted(() => {
      loadData()
    })
    return {
      title, hotList
    }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
</style>
